package com.sywb.chuangyebao.contract;

import org.bining.footstone.widget.PullToRefreshView;

public interface BaseRefreshContract {

    interface View extends BaseRecyclerContract.View {

        /**
         * 获取 PullToRefreshView
         */
        PullToRefreshView getPullToRefreshView();
    }

    abstract class Presenter<T extends View> extends BaseRecyclerContract.Presenter<T> {

        protected PullToRefreshView pullToRefreshView;

        @Override
        public void onStart() {
            super.onStart();
            pullToRefreshView = mView.getPullToRefreshView();

            if (pullToRefreshView != null) {
                pullToRefreshView.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() {
                    @Override
                    public void onRefresh(PullToRefreshView pullToRefreshLayout) {
                        onStartRefresh();
                    }
                });

                pullToRefreshView.setOnLoadMoreListener(new PullToRefreshView.OnLoadMoreListener() {
                    @Override
                    public void onLoadMore(PullToRefreshView pullToRefreshLayout) {
                        onStartLoadMore();
                    }
                });
            }
        }

        // @Override
        // public void onStartRefresh() {
        // new Handler().postDelayed(new Runnable() {
        // @Override
        // public void run() {
        // onEndRefresh();
        // }
        // }, 2000);
        // }

        @Override
        public void onEndRefresh() {
            super.onEndRefresh();
            if (pullToRefreshView != null) {
                pullToRefreshView.refreshFinish(true);
            }
        }

        // @Override
        // public void onStartLoadMore() {
        // new Handler().postDelayed(new Runnable() {
        // @Override
        // public void run() {
        // onEndLoadMore();
        // }
        // }, 2000);
        // }

        @Override
        public void onEndLoadMore() {
            super.onEndLoadMore();
            if (pullToRefreshView != null) {
                pullToRefreshView.loadmoreFinish(true);
            }
        }

    }
}
